<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author ThinkGem
-->
<template>
  <div>
    <BasicTable @register="registerTable" @row-click="handleTestDataChildRowClick">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar> </template>
      <template #firstColumn="{}"> </template>

      <template #logContent="{ record }">
        <div v-html="record.logContent"></div>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsBzLogList',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, watch } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { pmZoneAllocationBzLog } from '/@/api/proj/info/pmProjectinformation';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('test.testData');
  const { showMessage } = useMessage();
  const getTitle = {
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: t('报装日志'),
  };

  const props = defineProps({
    projectno: { type: String, default: '' },
  });

  watch(
    () => props.projectno,
    () => {
      reload();
    },
  );

  //配置表单内容
  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [],
  };

  //配置表格表头菜单
  const tableColumns: BasicColumn[] = [
    {
      title: t('操作员'),
      dataIndex: 'operatorName',
      key: 'a.operatorName',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('日志类容'),
      dataIndex: 'logContent',
      key: 'a.logContent',
      sorter: true,
      width: 200,
      align: 'left',
      slot: 'logContent',
    },
    {
      title: t('操作时间'),
      dataIndex: 'createTime',
      key: 'a.createTime',
      sorter: true,
      width: 150,
      align: 'left',
    },
  ];

  //配置表格右边操作按钮
  const actionColumn: BasicColumn = {
    width: 180,
    actions: (record: Recordable) => [],
  };

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload }] = useTable({
    api: pmZoneAllocationBzLog,
    beforeFetch: (params) => {
      params.projectno = props.projectno;
      return params;
    },
    afterFetch: (res) => {
      console.log(res, '111111');
      return res;
    },
    columns: tableColumns,
    //actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: false,
    canResize: true,
    pagination: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const res = await testDataDelete(record);
    showMessage(res.message);
    handleSuccess();
  }

  function handleSuccess() {
    reload();
  }
</script>
